From 570aa713b1b2becf7c06c89610c75d2cb119b532 Mon Sep 17 00:00:00 2001
From: Sebastien Castiel <sebastien@castiel.me>
Date: Wed, 6 Dec 2023 15:08:52 -0500
Subject: Delete expense

---
 src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx')

diff --git a/src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx b/src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx
index 934d346..0623f50 100644
--- a/src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx
+++ b/src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx
@@ -1,5 +1,5 @@
 import { ExpenseForm } from '@/components/expense-form'
-import { getExpense, getGroup, updateExpense } from '@/lib/api'
+import { deleteExpense, getExpense, getGroup, updateExpense } from '@/lib/api'
 import { expenseFormSchema } from '@/lib/schemas'
 import { notFound, redirect } from 'next/navigation'
 
@@ -20,11 +20,18 @@ export default async function EditExpensePage({
     redirect(`/groups/${groupId}`)
   }
 
+  async function deleteExpenseAction() {
+    'use server'
+    await deleteExpense(expenseId)
+    redirect(`/groups/${groupId}`)
+  }
+
   return (
     <ExpenseForm
       group={group}
       expense={expense}
       onSubmit={updateExpenseAction}
+      onDelete={deleteExpenseAction}
     />
   )
 }
-- 
cgit v1.3

